package shuashuami.hb.com.avtivity;

import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import cn.sharesdk.framework.Platform;
import cn.sharesdk.framework.ShareSDK;
import cn.sharesdk.wechat.friends.Wechat;
import shuashuami.hb.com.hbclient.R;
import shuashuami.hb.com.hdlibrary.util.ToastUtil;
import shuashuami.hb.com.share.ShareCUserInfo;
import shuashuami.hb.com.util.DataCleanManager;

public class CSettingActivity extends AbActivity  {

    private LinearLayout llCHangePassword, llYOnghuXieyi, llCLear;


    private TextView tvHuanCun;

    private Button loginOut;


    @Override
    protected void initUI() {
        setAbContentView(R.layout.activity_csetting);
        llCHangePassword = (LinearLayout) findViewById(R.id.ll_setting_change_password);
        llYOnghuXieyi = (LinearLayout) findViewById(R.id.ll_setting_yonghuxieyi);
        llCLear = (LinearLayout) findViewById(R.id.ll_setting_clear);
        tvHuanCun = (TextView) findViewById(R.id.tv_setting_huancun);

        loginOut = (Button) findViewById(R.id.btn_login_out);
    }

    @Override
    protected void initData() {
        setTitleBar("个人设置");
        setLeftView();
        try {
            tvHuanCun.setText(DataCleanManager.getTotalCacheSize(this));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void initListener() {
        llCHangePassword.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                openActivity(ChangePasswordActivity.class);
            }
        });
        llYOnghuXieyi.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                openActivity(YongHuXieyiActivity.class);
            }
        });

        llCLear.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                tvHuanCun.setText("0.0k");
                ToastUtil.showShort(getApplication(),"已清除");
                DataCleanManager.clearAllCache(CSettingActivity.this);
            }
        });
        loginOut.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Platform qzone = ShareSDK.getPlatform(Wechat.NAME);
                if (qzone.isAuthValid()) {
                    qzone.removeAccount(true);
                }
//                qzone.setPlatformActionListener(new PlatformActionListener() {
//                    @Override
//                    public void onComplete(Platform platform, int i, HashMap<String, Object> hashMap) {
//                        clear();
//                        openActivity(HbLoginAct.class);
//                        finishAllWithOutLast();
//                        finish();
//                    }
//
//                    @Override
//                    public void onError(Platform platform, int i, Throwable throwable) {
//
//                    }
//
//                    @Override
//                    public void onCancel(Platform platform, int i) {
//
//                    }
//                });
//                qzone.authorize();
//                qzone.showUser(null);
                clear();
                openActivity(HbLoginAct.class);
                finishAllWithOutLast();
                finish();

            }
        });



    }
    private void clear() {
        ShareCUserInfo shareCUserInfo  = new ShareCUserInfo(this);
        shareCUserInfo.clear();
    }

}
